﻿using Helper.Models;
using System;
using Helper;
using System.ComponentModel;
using System.Windows.Media.Imaging;

namespace Starehe.ViewModels
{
    public class ModifyStudentVM:StudentModel, IDataErrorInfo, INotifyPropertyChanged
    {
        BitmapImage photo = null;
        public ModifyStudentVM()
        {
        }
        
        public BitmapImage Photo
        {
            get { return this.photo; }

            set
            {
                if (value != this.photo)
                {
                    this.photo = value;
                    NotifyPropertyChanged("Photo");
                }
            }
        }

        public string Error
        {
            get { return null; }
        }
        
        public string this[string columnName]
        {
            get
            {
                switch (columnName)
                {
                    case "StudentID":
                        {
                            if (this.StudentID<=0)
                                return "Required value";
                            else if (!DataAccess.StudentExists(this.StudentID))
                                return "Student does not exist";
                            else 
                                return  null;
                        }
                    case "FirstName": return string.IsNullOrEmpty(this.FirstName) ? "Invalid value" : null;
                    case "MiddleName": return string.IsNullOrEmpty(this.MiddleName) ? "Invalid value" : null;
                    case "LastName": return string.IsNullOrEmpty(this.LastName) ? "Invalid value" : null;
                    case "Email": return string.IsNullOrEmpty(this.Email) ? "Invalid value" : null;
                    case "GuardianPhoneNo": return string.IsNullOrEmpty(this.GuardianPhoneNo) ? "Invalid value" : null;
                    case "NameOfGuardian": return string.IsNullOrEmpty(this.NameOfGuardian) ? "Invalid value" : null;
                    case "DateOfAdmission": return (DateOfAdmission == null) ? "Invalid value" : null;
                    case "DateOfBirth": return (DateOfBirth == null) ? "Invalid value" : null;
                }
                return null;
            }
        }
    }
}
